package com.hopes.bizz.common.core.util;

import com.hopes.bizz.common.core.constant.CommonEnum;
import com.hopes.boss.common.core.exception.BizException;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.function.Function;

/**
 * 日期函数
 *
 * @author xk
 * @version 1.0.0 2020/6/8 23:03
 */
public class DateUtils {

    /**
     * 格式化到年（2014）
     */
    public static final String FORMAT_YEAR = "yyyy";
    /**
     * 格式化到月（2014-09）
     */
    public static final String FORMAT_MOUTH = "yyyy-MM";
    /**
     * 格式化到天（2014-09-15）
     */
    public static final String FORMAT_DAY = "yyyy-MM-dd";
    /**
     * 格式化到天（2014-09-15）
     */
    public static final String FORMAT_HOUR = "yyyy-MM-dd HH";
    /**
     * 格式化到分钟（2014-09-15 13:35）
     */
    public static final String FORMAT_MINUTE = "yyyy-MM-dd HH:mm";
    /**
     * 格式化到秒(2014-09-15 13:35:22)
     */
    public static final String FORMAT_SECOND = "yyyy-MM-dd HH:mm:ss";

    public static final String FORMAT_TIME = "HH:mm:ss";

    public static final String FORMAT_SIMPLE_HOUR = "yyyyMMddHH";

    public static final String FORMAT_SIMPLE_MINUTE = "yyyyMMddHHmm";

    public static final String FORMAT_SIMPLE_SECOND = "yyyyMMddHHmmss";

    /**
     * 一分钟前
     */
    public static final int A_MINUTE_AGO = -1;
    /**
     * 零
     */
    private static final int ZERO = 0;

    /**
     * 季度的开始月份
     */
    public static final int[] SEASON_MONTH_BEGIN = {0, 3, 6, 9};

    /**
     * 禁止外部实例化
     */
    private DateUtils() {

    }



    /**
     * 日期保留到本月的第一天
     * @param date
     * @return
     */
    public static Date dateLimitMonth(Date date) {
        final Calendar instance = Calendar.getInstance();
        instance.setTime(date);
        instance.set(Calendar.MILLISECOND, ZERO);
        instance.set(Calendar.SECOND, ZERO);
        instance.set(Calendar.MINUTE, ZERO);
        instance.set(Calendar.HOUR_OF_DAY, ZERO);
        instance.set(Calendar.DAY_OF_MONTH, 1);
        return instance.getTime();
    }


    /**
     * 日期保留到天后返回
     * @param date
     * @return 如 2020-10-09 16:42:23 ==> 2020-10-09 00:00:00
     */
    public static Date dateLimitDay(Date date){
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.MILLISECOND, ZERO);
        calendar.set(Calendar.SECOND, ZERO);
        calendar.set(Calendar.MINUTE, ZERO);
        calendar.set(Calendar.HOUR_OF_DAY, ZERO);
        return calendar.getTime();
    }

    /**
     * 日期保留到小时后返回
     * @param date
     * @return 如 2020-10-09 16:42:23 ==> 2020-10-09 16:00:00
     */
    public static Date dateLimitHour(Date date){
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.MILLISECOND, ZERO);
        calendar.set(Calendar.SECOND, ZERO);
        calendar.set(Calendar.MINUTE, ZERO);
        return calendar.getTime();
    }

    /**
     * 日期保留到分钟后返回
     * @param date
     * @return 如 2020-10-09 16:42:23 ==> 2020-10-09 16:42:00
     */
    public static Date dateLimitMinute(Date date){
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.MILLISECOND, ZERO);
        calendar.set(Calendar.SECOND, ZERO);
        return calendar.getTime();
    }

    /**
     * 将String类型日期转换为Date类型的日期 <br>
     *
     * @param strDate
     * @param formatter
     * @return
     * @author Hunter
     * @version [1.0.0, 2015年10月22日]
     * @since [1.0.0]
     */
    public static Date parseDateByStr(String strDate, String formatter) {
        if (formatter == null || formatter.trim().equals("")) {
            formatter = "yyyy-MM-dd";
        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(formatter);
        // 必须捕获异常
        try {
            Date date = simpleDateFormat.parse(strDate);
            return date;
        } catch (ParseException ex) {
            ex.printStackTrace();
        }
        return null;
    }

    /**
     * 获取日期的对应字段
     * @param date
     * @param field
     * @return
     */
    public static int get(Date date, int field){
        Calendar calendar = Calendar.getInstance();
        if(date != null){
            calendar.setTime(date);
        }
        return calendar.get(field);
    }

    /**
     * 设置日期的对应字段
     * @param date
     * @param field
     * @return
     */
    public static Date set(Date date, int field, int value){
        Calendar calendar = Calendar.getInstance();
        if(date != null){
            calendar.setTime(date);
        }
        calendar.set(field, value);
        return calendar.getTime();
    }

    /**
     * 添加
     * @param date
     * @param field
     * @param amount
     * @return
     */
    public static Date add(Date date, int field, int amount) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(field, amount);
        return cal.getTime();
    }

    /**
     * 根据传入的日期以及天数计算（相应天数前/后）并返回日期<br>
     *
     * @param date
     * @param days
     * @return 计算后的日期
     * eg: 入参：Thu Oct 22 14:57:34 CST 2015 , -1 出参：Wed Oct 21 14:57:34 CST 2015
     * @author Hunter
     * @version [1.0.0, 2015年10月22日]
     * @since [1.0.0]
     */
    public static Date addDate(Date date, int days) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.DATE, days);
        return cal.getTime();
    }

    /**
     * 取得两个时间相隔的天数,如果后一个日期较小则返回负数 <br>
     *
     * @param startDate
     * @param endDate
     * @return 相差的天数
     * @author Hunter
     * @version [1.0.0, 2015年10月22日]
     * @since [1.0.0]
     */
    public static int getIntervalDays(Date startDate, Date endDate) {
        Calendar fromCalendar = Calendar.getInstance();
        fromCalendar.setTime(startDate);
        fromCalendar.set(Calendar.HOUR_OF_DAY, 0);
        fromCalendar.set(Calendar.MINUTE, 0);
        fromCalendar.set(Calendar.SECOND, 0);
        fromCalendar.set(Calendar.MILLISECOND, 0);

        Calendar toCalendar = Calendar.getInstance();
        toCalendar.setTime(endDate);
        toCalendar.set(Calendar.HOUR_OF_DAY, 0);
        toCalendar.set(Calendar.MINUTE, 0);
        toCalendar.set(Calendar.SECOND, 0);
        toCalendar.set(Calendar.MILLISECOND, 0);
        return (int) ((toCalendar.getTime().getTime() - fromCalendar.getTime().getTime()) / (1000 * 60 * 60 * 24));
    }

    public static double getIntervalHours(Date startDate, Date endDate) {
        long subSeconds = getIntervalSeconds(startDate, endDate);
        BigDecimal b = new BigDecimal(subSeconds / 3600.0D);
        return b.setScale(2, RoundingMode.HALF_UP).doubleValue();
    }

    public static long getIntervalSeconds(Date startDate, Date endDate) {
        String startDateStr = limitSecond(startDate);
        String endDateStr = limitSecond(endDate);
        //计算秒数
        LocalDateTime localDateTimeStart = LocalDateTime.parse(startDateStr, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        LocalDateTime localDateTimeEnd = LocalDateTime.parse(endDateStr, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        return Duration.between(localDateTimeStart, localDateTimeEnd).toMillis() / 1000;
    }

    /**
     * 根据传入的日期以及分钟数计算（相应分钟数前/后）并返回日期<br>
     *
     * @param date
     * @param minutes
     * @return 计算后的日期
     * eg: 入参：Thu Oct 22 14:57:34 CST 2015 , -1 出参：Wed Oct 21 14:56:34 CST 2015
     * @author Hunter
     * @version [1.0.0, 2015年10月22日]
     * @since [1.0.0]
     */
    public static Date addMinute(Date date, int minutes) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.MINUTE, minutes);
        return cal.getTime();
    }

    /**
     * 根据传入的日期以及小时数计算（相应小时数前/后）并返回日期<br>
     */
    public static Date addHour(Date date, int hours) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.HOUR, hours);
        return cal.getTime();
    }

    /**
     * 取得日期：年
     *
     * @param date
     * @return
     */
    public static int getYear(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        int year = c.get(Calendar.YEAR);
        return year;
    }

    /**
     * 取得日期：月
     *
     * @param date
     * @return
     */
    public static int getMonth(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        int month = c.get(Calendar.MONTH) + 1;
        return month;
    }

    /**
     * 计算出日期一比日期二小多少年
     *
     * @param startDate
     * @param endDate
     * @return
     */
    public static int getIntervalYear(Date startDate, Date endDate) {
        Calendar date1 = Calendar.getInstance();
        date1.setTime(startDate);
        Calendar date2 = Calendar.getInstance();
        date2.setTime(endDate);
        return date2.get(Calendar.YEAR) - date1.get(Calendar.YEAR);
    }

    /**
     * 将String类型日期转换为Date类型的日期 <br>
     *
     * @param strDate
     * @param formatter
     * @return
     * @author Hunter
     * @version [1.0.0, 2015年10月22日]
     * @since [1.0.0]
     */
    public static Date parseDate(String strDate, String formatter) {
        if (formatter == null || "".equals(formatter.trim())) {
            formatter = "yyyy-MM-dd";
        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(formatter);
        // 必须捕获异常
        try {
            return simpleDateFormat.parse(strDate);
        } catch (ParseException ex) {
            throw new BizException("转换失败" + ex.getMessage());
        }
    }

    /**
     * 将String类型日期转换为Date类型的日期 <br>
     *
     * @param startEndEnum
     * @param strDate
     * @author Hunter
     * @version [1.0.0, 2015年10月22日]
     * @since [1.0.0]
     */
    public static Date parseDate(CommonEnum.StartEndEnum startEndEnum, String strDate) {
        if (startEndEnum.equals(CommonEnum.StartEndEnum.END)) {
            strDate = strDate + " 23:59:59";
        } else {
            strDate = strDate + " 00:00:00";
        }
        return parseDate(strDate, FORMAT_SECOND);
    }

    /**
     * 获取给定日期的开始时间，如果不传则以当前日期的开始时间
     *
     * @param date
     * @return 返回类似 2019-03-23 00:00:00:000
     */
    public static Date getDateStart(Date date) {
        if (date == null) {
            date = new Date();
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    public static Date[] getMothStartEndDate(Date date) {
        final Date[] result = new Date[2];
        final Calendar instance = Calendar.getInstance();
        instance.setTime(date);
        instance.set(Calendar.DAY_OF_MONTH, 1);
        instance.set(Calendar.HOUR_OF_DAY, 0);
        instance.set(Calendar.MINUTE, 0);
        instance.set(Calendar.SECOND, 0);
        instance.set(Calendar.MILLISECOND, 0);
        result[0] = instance.getTime();
        instance.add(Calendar.MONTH, 1);
        instance.set(Calendar.MILLISECOND, -1);
        result[1] = instance.getTime();
        return result;
    }

    public static Date[] getYearStartEndDate(Date date) {
        final Date[] result = new Date[2];
        final Calendar instance = Calendar.getInstance();
        instance.setTime(date);
        instance.set(Calendar.MONTH, 0);
        instance.set(Calendar.DAY_OF_MONTH, 1);
        instance.set(Calendar.HOUR_OF_DAY, 0);
        instance.set(Calendar.MINUTE, 0);
        instance.set(Calendar.SECOND, 0);
        instance.set(Calendar.MILLISECOND, 0);
        result[0] = instance.getTime();
        instance.add(Calendar.YEAR, 1);
        instance.set(Calendar.MILLISECOND, -1);
        result[1] = instance.getTime();
        return result;
    }


    public static Date getHourStart(Date date) {
        if (date == null) {
            date = new Date();
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    public static Date getHourEnd(Date date) {
        if (date == null) {
            date = new Date();
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        calendar.set(Calendar.MILLISECOND, 999);
        return calendar.getTime();
    }

    public static Date getMinStart(Date date) {
        if (date == null) {
            date = new Date();
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    /**
     * 获取给定日期的开始时间，如果不传则以当前日期的开始时间
     *
     * @param date
     * @return 返回类似 2019-03-23 23:59:59:999
     */
    public static Date getDateEnd(Date date) {
        if (date == null) {
            date = new Date();
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        calendar.set(Calendar.MILLISECOND, 999);
        return calendar.getTime();
    }


    /**
     * 格式化到天 <br>
     *
     * @param date
     * @return 2014-09-15
     * @author Hunter
     * @version [1.0.0, 2015年10月22日]
     * @since [1.0.0]
     */
    public static String limitDay(Date date) {
        return formatDate(date, FORMAT_DAY);
    }

    /**
     * 格式化到月 <br>
     *
     * @param date
     * @return 2014-09
     * @author Hunter
     * @version [1.0.0, 2015年10月22日]
     * @since [1.0.0]
     */
    public static String limitMouth(Date date) {
        return formatDate(date, FORMAT_MOUTH);
    }

    /**
     * 格式化到年 <br>
     *
     * @param date
     * @return 2014-09-15
     * @author Hunter
     * @version [1.0.0, 2015年10月22日]
     * @since [1.0.0]
     */
    public static String limitYear(Date date) {
        return formatDate(date, FORMAT_YEAR);
    }

    /**
     * 以指定格式格式化时间 <br>
     *
     * @param date   时间
     * @param format 格式
     * @return 格式化的时间字符串
     * eg:入参：当前时间，yyyy-MM-dd；输出：YYYY-MM-DD
     * @author Hunter
     * @version [1.0.0, 2015年10月22日]
     * @since [1.0.0]
     */
    public static String formatDate(Date date, String format) {
        if (date == null) {
            return null;
        }
        if (format == null || "".equals(format.trim())) {
            format = "yyyy-MM-dd";
        }
        SimpleDateFormat dateFormatter = new SimpleDateFormat(format);
        return dateFormatter.format(date);
    }

    /**
     * 格式化到月天 MM-dd <br>
     *
     * @param date
     * @return 2014-09-15
     * @author Hunter
     * @version [1.0.0, 2015年10月22日]
     * @since [1.0.0]
     */
    public static String limitMonAndDay(Date date) {
        return formatDate(date, "MM-dd");
    }

    /**
     * 格式化到分钟 <br>
     *
     * @param date
     * @return 2014-09-15 13:35
     * @author Hunter
     * @version [1.0.0, 2015年10月22日]
     * @since [1.0.0]
     */
    public static String limitMinute(Date date) {
        return formatDate(date, FORMAT_MINUTE);
    }

    /**
     * 格式化到小时 <br>
     *
     * @param date
     * @return 2014-09-15 13:35
     * @author Hunter
     * @version [1.0.0, 2015年10月22日]
     * @since [1.0.0]
     */
    public static String limitHour(Date date) {
        return formatDate(date, FORMAT_HOUR);
    }

    /**
     * 格式化到秒钟 <br>
     *
     * @param date
     * @return 2014-09-15 13:35
     * @author Hunter
     * @version [1.0.0, 2020年07月22日]
     * @since [1.0.0]
     */
    public static String limitSecond(Date date) {
        return formatDate(date, FORMAT_SECOND);
    }

    /**
     * 取得两个时间时间差,如果后一个日期较小则返回负数 <br>
     *
     * @param startDate
     * @param endDate
     * @return 相差的天数
     * @author mkf
     * @version [1.0.0, 2015年10月22日]
     * @since [1.0.0]
     */
    public static String getIntervalStr(Date startDate, Date endDate) {
        long startTime = startDate.getTime();
        long endTime = endDate.getTime();
        long result = endTime - startTime; //获取两时间相差的毫秒数
        long day = result / (24 * 60 * 60 * 1000);
        long hour = (result / (60 * 60 * 1000) - day * 24);
        long min = ((result / (60 * 1000)) - day * 24 * 60 - hour * 60);
        long s = (result / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
        return "" + day + "天" + hour + "小时" + min + "分" + s + "秒";
    }

    /**
     * 取得两个时间分钟差,如果后一个日期较小则返回负数 <br>
     *
     * @param startDate
     * @param endDate
     * @return 相差的天数
     * @author mkf
     * @version [1.0.0, 2015年10月22日]
     * @since [1.0.0]
     */
    public static Long getIntervalMin(Date startDate, Date endDate) {
        long startTime = startDate.getTime();
        long endTime = endDate.getTime();
        long result = endTime - startTime;
        return (result / (60 * 1000));
    }

    /**
     * 通过毫秒数获取时间
     * @param milliSecond 毫秒数
     * @return 时间
     */
    public static Date getTimeStrByMilliSecond (Long milliSecond) {
        Date date = new Date();
        date.setTime(milliSecond);
        return date;
    }

    public static String getTimeStrBySecond(Long second) {
        if (null != second && second == 0) {
            return "0秒";
        } else if (second != null && second > 0) {
            StringBuilder res = new StringBuilder();
            Long durationMinute = second / 60;
            Long hour = durationMinute / 60;
            Long day = hour / 24;
            if (day > 0) {
                res.append(day).append("天");
                res.append(second / 60 / 60 % 24).append("小时");
                res.append(second / 60 % 60).append("分钟");
                res.append(second % 60).append("秒");
            } else if (hour > 0) {
                res.append(hour).append("小时");
                res.append(second / 60 % 60).append("分钟");
                res.append(second % 60).append("秒");
            } else if (durationMinute > 0) {
                res.append(durationMinute).append("分钟");
                res.append(second % 60).append("秒");
            } else {
                res.append(second).append("秒");
            }
            return res.toString();
        }
        return "";
    }

    /**
     * 获取给定日期的上个月月份
     *
     * @param date
     * @return 返回类似 2023-02
     */
    public static Date getLastMouthStartDay(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.MONTH, 1);
        calendar.set(Calendar.SECOND, ZERO);
        calendar.set(Calendar.MINUTE, ZERO);
        calendar.set(Calendar.MILLISECOND, ZERO);
        calendar.set(Calendar.HOUR_OF_DAY, ZERO);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        return calendar.getTime();
    }

    /**
     * 获取给定日期的上个月月份
     *
     * @param date
     * @return 返回类似 2023-02
     */
    public static Date getLastMouthEndDay(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.MONTH, 1);
        calendar.set(Calendar.SECOND, ZERO);
        calendar.set(Calendar.MINUTE, ZERO);
        calendar.set(Calendar.MILLISECOND, ZERO);
        calendar.set(Calendar.HOUR_OF_DAY, ZERO);
        calendar.set(Calendar.DAY_OF_MONTH, 30);
        return calendar.getTime();
    }

    /**
     * 获取一个时间范围
     * */
    public static Set<String> makeBeginTimeToEndTimeList(Date beginTime, Date endTime, String formatStr){

        SimpleDateFormat sdf = new SimpleDateFormat(formatStr);
        List<Date> lDate = new ArrayList<>();
        //加入开始时间
        lDate.add(beginTime);
        Calendar calBegin = Calendar.getInstance();
        // 使用给定的 Date 设置此 Calendar 的时间
        calBegin.setTime(beginTime);
        Calendar calEnd = Calendar.getInstance();
        // 使用给定的 Date 设置此 Calendar 的时间
        calEnd.setTime(endTime);
        // 测试此日期是否在指定日期之后
        while (endTime.after(calBegin.getTime()))
        {
            // 根据日历的规则，为给定的日历字段添加或减去指定的时间量
            calBegin.add(Calendar.DAY_OF_MONTH, 1);
            lDate.add(calBegin.getTime());
        }
        Set<String> timeStringList=new TreeSet<>();
        for (Date datePes :lDate){
            String format = sdf.format(datePes);
            timeStringList.add(format);
        }

        return timeStringList;
    }

    /**
     * 获取当月第一天
     * */
    public static Date getMonthFirstDay() {
        Calendar cal = Calendar.getInstance();
        cal.setTime(DateUtils.dateLimitDay(cal.getTime()));
        cal.set(Calendar.DAY_OF_MONTH, 1);

        return cal.getTime();
    }

    /**
     * 获取当月所有天
     * @return
     */
    public static List<String> getDayListOfMonth() {
        List<String> list = new ArrayList<>();
        Calendar aCalendar = Calendar.getInstance(Locale.CHINA);
        int day = aCalendar.getActualMaximum(Calendar.DATE);
        aCalendar.set(Calendar.DATE,1);
        for (int i = 1; i <= day; i++) {
            String aDate = formatDate(aCalendar.getTime(), FORMAT_DAY);
            list.add(aDate);
            aCalendar.add(Calendar.DATE,1);
        }
        return list;
    }
    /**
     * myDate 起始时间，默认当前时间
     * num 获取x个月前后的月份，x为参数，负数表示往前几个月
     * dft 返回的格式，默认"yyyyMM"
     * @return
     */
    public static String getLastMonth(Date myDate, int num, SimpleDateFormat dft) {
        Calendar cal = Calendar.getInstance();
        if (Objects.nonNull(myDate)) {
            cal.setTime(myDate);
        }
        cal.add(Calendar.MONTH, num);
        if (Objects.isNull(dft)){
            dft = new SimpleDateFormat("yyyyMM");
        }
        String lastMonth = dft.format(cal.getTime());
        return lastMonth;
    }


    public static int getMonthMaxDay(int month) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(dateLimitDay(cal.getTime()));
        cal.set(Calendar.MONTH, month);
        cal.set(Calendar.DAY_OF_MONTH, 1);
        cal.add(Calendar.MONTH, 1);
        cal.add(Calendar.DAY_OF_MONTH, -1);
        return cal.get(Calendar.DAY_OF_MONTH);
    }

    /**
     * 处理时间
     *
     * @param beginTime 开始时间
     * @param endTime   结束时间
     * @param mapper    函数，格式化时间
     * @param calendar  类型 如: Calendar.DAY_OF_YEAR, Calendar.HOUR_OF_DAY 等
     * @param step      步长
     * @return 结果
     */
    public static List<String> handlerDateTime(Date beginTime, Date endTime, Function<Date, String> mapper, Integer calendar, Integer step) {
        final List<String> list = new ArrayList<>();
        final Calendar instance = Calendar.getInstance();
        instance.setTime(beginTime);
        while (instance.getTimeInMillis() < endTime.getTime()) {
            final String apply = mapper.apply(instance.getTime());
            list.add(apply);
            instance.add(calendar, step);
        }
        return list;
    }


}
